<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ include file="../../attr.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="${ctx}/css/sapar.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css"/>
    <link href="${ctx}/css/select2.min.css" rel="stylesheet" />


    <style type="text/css">
        td {
            text-align: center;
        }

        .top{
            table-layout: fixed;
        }
        .body{
            table-layout: fixed;
        }
    </style>
</head>
<body>
<div class="tab-content-item">

    <audio src="../../audio/Beep_Short.mp3" id="audio"></audio><!-- 成功提示音 -->
    <audio src="../../audio/Alarm_Clock (1).mp3" id="audio1"></audio><!-- 失败提示音 -->
        <div class="kv-item clearfix">


            <div class="kv-item clearfix">
                <div class="kv-item-content">
                    <label><span class="impInfo">*</span>科室：</label>
                    <select id="packageDepartid" name="packageDepartid" onChange="showPack(true)">
                        <c:if test="${deptList !=null}">
                            <option value="0">请选择科室</option>
                            <c:forEach items="${deptList }" var="deptment">
                                <option  <c:if test="${selected==deptment.departmentId}">selected</c:if>  value="${deptment.departmentId}">${deptment.departmentName}</option>
                            </c:forEach>
                        </c:if>
                    </select>
                </div>
                <div class="kv-item-content">
                    <label>包筛选：</label>
                    <div class="kv-item-content" style="line-height:30px;">
                        <input style="width: 100px" name="packageName" id="packageName" class="gui-input" placeholder="包简码" type="text" value="">
                    </div>
                </div>
                <div class="kv-item-content" style="padding-right: 30px">
                    <a   href="javascript:;" class="sapar-btn sapar-btn-recom query-btn" id="baocun"
                        onclick="do_save()">保存</a>
                </div>
            </div>

            <div class="kv-item-content" id="app">
                <%--<label>网篮条码：</label>--%>
                <%--<div style="width: 216px" class="kv-item-content">--%>
                    <%--<input  type="text" maxLength="7" v-model=huishouWanglanTiaoma name="huishouWanglanTiaoma" id="wanglantiaoma"--%>
                           <%--placeholder="网篮条码" autofocus="autofocus" @keyup.enter="enterFun" >--%>
                <%--</div>--%>
                <%--<label>网篮名称：</label>--%>
                <%--<div class="kv-item-content">--%>
                    <%--<input type="text" v-model="huishouWanglanMingcheng" name="huishouWanglanMingcheng" placeholder="网篮名称"--%>
                           <%--readonly="readonly" id="wanglanMingcheng">--%>
                <%--</div>--%>

            </div>
        </div>


        <div class="table">
            <div>
                <table class="top">
                    <thead>
                    <tr>
                        <th >部门</th>
                        <th>包名</th>
                        <th>数量</th>
                        <th>外包装类型</th>
                        <th>灭菌方式</th>
                    </tr>
                    </thead>
                </table>
            </div>

            <!--表格具体内容-->
            <div class="table-box" style="height: 520px;overflow-y: scroll">
                <table id="tbpck" class="body">

                    <tbody style="height: 520px" id="body_list">

                    <%--<c:if test="${packages !=null}">--%>
                        <%--<c:forEach items="${packages }" var="packages">--%>
                            <%--<td>packages.packageName</td>--%>
                            <%--<td></td>--%>
                            <%--<td></td>--%>
                        <%--</c:forEach>--%>
                    <%--</c:if>--%>

                    </tbody>
                </table>
            </div>
            <%--<div>--%>
                <%--<input id="leftPage" class="butLeft" type="button" value="上一页"/>--%>
                <%--<input id="rightPage" class="butRight" type="button" value="下一页"/>--%>
                <%--<span>到第&nbsp;</span><input id="goPage" class="textBox" type="text" value="1"/><span--%>
                    <%--style="margin-left: 4px;">页&nbsp;</span>--%>
                <%--<input id="sureBut" class="sure" type="button" value="确定"/>--%>
                <%--<span>共</span><span class="totalPages" id="totalNum">0</span><span>&nbsp;页</span>--%>
            <%--</div>--%>
        </div>
</div>

</body>
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/vue.min.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
<%@ include file="../../js.jsp" %>
<script type="text/javascript">

//    window.onload = function () {
//        $("#wanglantiaoma").focus();
//    };
    var data = ${packages};
    var miejun = ${miejun};
    shuzi(data,miejun);
    $(function () {

        $('select').select2();

        $("#back").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });
        $("#save").click(function () {
            do_save();
        });

        $(document).keydown(function (event) {
            var oPlay0 = document.getElementById("audio");
            var oPlay1 = document.getElementById("audio1");
            var packageName = $("input[name='packageName']").val();
            if (event.keyCode == 13) {

                if ($("#packageName").is(":focus") ) {
                    showPack(false);
                    $("#wanglantiaoma").focus();
                }
            }
        });


    });

    var oPlay0 = document.getElementById("audio");
    var oPlay1 = document.getElementById("audio1");

    var vm = new Vue({
        el:'#app',
        data : {
            huishouWanglanTiaoma: '',
            huishouWanglanMingcheng: '',
        },
        methods : {
            enterFun: function () {
                var that = this;
                if ($("#wanglantiaoma").is(":focus") && !isNullOrEmpty(that.huishouWanglanTiaoma)) {
                    $.get("/wutiaoma/findwanglan.do?huishouWanglanTiaoma=" + that.huishouWanglanTiaoma,function(data){
                        if (data.status == true) {
                            oPlay0.play();
                            that.huishouWanglanMingcheng = data.zsWanglan.wlMingcheng;
                            that.addpackage();
                        }else if (data.status == false) {
                            oPlay1.play();
                            that.huishouWanglanTiaoma = "";
                            that.huishouWanglanMingcheng = "";
                        }
                    })

                }


            },
        }
    })


    function showPack(data) {
        if(data==true){
            $("#packageName").val("");
        }
        $("#packageName").focus();
        var url = "${ctx}/wutiaoma/findHuishouPackageByDepart.do?packageCode=" + $("#packageName").val() + "&packageDepartid=" + $("#packageDepartid").val();
        $.ajax({
            type: "POST",
            url: url,
            data: $('#dataHuiShouForm').serialize(),// 你的formid
            error: function (request) {
                layer.alert("网络故障，请稍后再试!");
            },
            success: function (datas) {
                if (datas.status == "true") {
                    var data = datas.packages;
                    var miejun = datas.miejun;
                    shuzi(data,miejun);
                }
            }
        });
    }

    function shuzi(data,miejun){
        $("#tbpck tbody").empty();
        var str = "";
        for (var i = 0; i < data.length; i++) {
            var dep = data[i].tbDepartment;
            var deptname;
            var miejunIn = data[i].packageMiejunFangshi;

            var miejunfangshi = miejun[miejunIn].dictName;
            var dabao = data[i].zsDabao;
            var dabaoName = "";
            if(dabao!=null){
                dabaoName = dabao.dabaoName;
            }
            if (dep != null) {
                deptname = dep.departmentName;
            } else {
                deptname = "";
            }
            str += '<tr>' +
                '<td>' + deptname + '</td>' +
                '<td class="text-left">' + data[i].packageName + '</td>' +
                '<td><input type="hidden" name="deptName" value="' + deptname + '"/>' +
                '<input type="hidden" name="pid" value="' + data[i].packageId + '"/>' +
                '<input style="text-align:center" type="text" name="key" maxlength="3" onkeyup="this.value=this.value.replace(/\\D/g,\'\')" class="gui-input"/>' +
                '<input type="hidden" name="pname" value="' + data[i].packageName + '"/></td>' +
                '<td>'+dabaoName+'</td>' +
                '<td>'+miejunfangshi+'</td></tr>'
        }
        $("#tbpck tbody").append(str);
    }


    function do_save() {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        var rtnJson = new Array();
        var check = true;
        var options = $("#packageDepartid option:selected");
        if(options==null){
            alert("请选择科室");
        }
        debugger
//        var huishouWanglanTiaoma = $("#wanglantiaoma").val();
//        var huishouWanglanMingcheng = $("#wanglanMingcheng").val();
        var keshi = $("#packageDepartid").val()
        if (keshi != "0") {
            var keshiName = $("#packageDepartid").find("option:selected").text();
        }else if(keshi == "0"){
            check = false;
            alert("请选择科室进行回收，方便统计");
        }
//        if(""==huishouWanglanTiaoma){
//            alert("请录入网篮")
//            check = false
//        }
//        if(""==huishouWanglanMingcheng){
//            alert("请录入正确的网篮")
//            check = false
//        }
        $('input[name="key"]').each(function () {
            var depVal = $(this).prev().prev().val();
            var id = $(this).prev().val();
            var name = $(this).next().val();
            var val = $(this).val();
            var depId = $("#packageDepartid").val();
            if (val != '') {
                var obj = new Object();
                obj.keshi_packId = keshi+id;
                obj.keshi = keshi;
                obj.keshiName = keshiName;
                obj.packId = id;
                obj.packName = name;
                obj.packNum = val;
//                obj.depId = depId;
//                obj.depVal = depVal;
//                obj.huishouWanglanTiaoma = huishouWanglanTiaoma;
//                obj.huishouWanglanMingcheng = huishouWanglanMingcheng;
                rtnJson.push(obj);
                //console.log(rtnJson);
            }
        });
        if(check){
            parent.callbackData(rtnJson);
            showPack(false);
            $("#wanglantiaoma").val("");
            $("#wanglanMingcheng").val("");
            $("#packageName").val("");
            //关闭界面
//            parent.layer.close(index);
        }else{

        }

    }



    //判断是否为空
    function isNullOrEmpty(strVal) {
        if (strVal != null) {
            strVal = strVal.replace(/(^\s*)|(\s*$)/g, "");
        }
        if (strVal == '' || strVal == null || strVal == undefined) {
            return true;
        } else {
            return false;
        }
    }

</script>
</html>